package com.novax.ex.activity.provider.filter;

import lombok.extern.slf4j.Slf4j;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import jakarta.servlet.*;
import jakarta.servlet.annotation.WebFilter;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @description: 健康检查filter
 * @author: Wade
 * @date: 12/13/22 12:01 PM
 * @param:
 * @return:
 **/
@WebFilter(urlPatterns = "/*")
@Slf4j
@Component
@Order(0)
public class HealthFilter implements Filter {
    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        HttpServletRequest req = (HttpServletRequest) request;
        String requestURI = req.getRequestURI();
        if ("/health/check".equals(requestURI)) {
            HttpServletResponse res = (HttpServletResponse) response;
            res.getWriter().write("OK");
            return;
        }
        chain.doFilter(request, response);
    }
}

